import request from '@/utils/request'
import store from '@/store'

// 查询HeadSdPool列表
export function listHeadSdPool(query) {
    return request({
        url: '/api/v1/pool/headSDList',
        method: 'get',
        params: query
    }).then(function (res) {

        let sexOptions = store.getters.parameter.sys_user_sex; 
        
        res.data.list.forEach((item, index) => {
            // console.log(item)
            for (let key in item) {
                // console.log(key + '---' + item[key])
                 
                if (key == "sex") {
                    item[key] = getDictLabelByValue(item[key], sexOptions)
                }
                 
            }

            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}

function getDictLabelByValue(value, dict_list) {
    let dictLabel = "";
    if (dict_list) {
        dict_list.forEach((_item, index) => {
            if (_item.dictValue == value) {
                dictLabel = _item.dictLabel
            }
        })
        return dictLabel;
    } else {
        console.log(value);
        return;
    }

}

// 查询HeadSdPool详细
export function getHeadSdPool(sdPoolId) {
    return request({
        url: '/api/v1/pool/headSD/' + sdPoolId,
        method: 'get'
    })
}


// 新增HeadSdPool
export function addHeadSdPool(data) {
    return request({
        url: '/api/v1/pool/headSD',
        method: 'post',
        data: data
    })
}

// 修改HeadSdPool
export function updateHeadSdPool(data) {
    return request({
        url: '/api/v1/pool/headSD',
        method: 'put',
        data: data
    })
}

// 删除HeadSdPool
export function delHeadSdPool(sdPoolId) {
    return request({
        url: '/api/v1/pool/headSD/' + sdPoolId,
        method: 'delete'
    })
}